/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing_class;

import java.io.IOException;
import java.net.SocketException;
import java.net.UnknownHostException;
import services.ConvIntByte;
import stendcontrol.TransmitListener;
import stendcontrol.UdpServer;

/**
 *
 * @author minaev
 */
public class UDPServer_Test {

    public static void main(String[] args)
            throws SocketException, UnknownHostException, InterruptedException, IOException {



        TransmitListener tl = new TransmitListener() {
            @Override
            public void transmitPerformed(byte[] buf, int len) {
                if (len == 11) {
                    System.out.println((buf[7] * (1 << 24)
                            + ConvIntByte.byte2Int(buf[8]) * (1 << 16)
                            + ConvIntByte.byte2Int(buf[9]) * (1 << 8)
                            + ConvIntByte.byte2Int(buf[10])));
                }
            }
        };

        byte[] ip = {ConvIntByte.int2Byte(192),
            ConvIntByte.int2Byte(168),
            ConvIntByte.int2Byte(0),
            ConvIntByte.int2Byte(255)};

        UdpServer userv = new UdpServer(ip, 0xc93A, 0xc939);
        userv.addTransmitListener(tl);
        new Thread(userv).start();
        userv.startTransmitToExp();
        //Thread udp_tread = new Thread(userv);
        UDP_Fluder udpf = new UDP_Fluder("192.168.0.255", 1000);
        udpf.start();

        Thread.sleep(5000);
        udpf.shutdown();


        for (int i = 0; i < 20; i++) {
            ip[0] += i;
            userv.sendPacket(ip, ip.length);
            Thread.sleep(100);
        }
        userv.stopUDPThread();


    }
}
